﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BesAsm.Framework.Reporting
{
  public partial class MessengerUserControl : UserControl
  {
    public MessengerUserControl()
    {
      InitializeComponent();
      txtMessages.Clear();
      
      while (MessageQueue.MessageCount > 0)
      {
        ReportMessage(MessageQueue.GetMessage());
      }
      MessageQueue.MessageQueued += new MessageReportedEventHandler(ReportMessageHandler);
      
    }

    private void ReportMessage(ReportableMessage reportableMessage)
    {
      txtMessages.AppendText(reportableMessage.CreationTime.ToString(@"HH:mm tt: "));
      txtMessages.AppendText(reportableMessage.Description);
      txtMessages.AppendText(Environment.NewLine);
      txtMessages.Focus();
      txtMessages.ScrollToCaret();
    }

    private void ReportMessageHandler(object sender, MessageReportedArgs e)
    {
      ReportMessage(e.Message);
    }    

    
  }
}
